package com.yhm.action;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.ActionSupport;
import com.yhm.model.Dep;
import com.yhm.service.DepManager;


@SuppressWarnings("serial")
@Component("dep")
@Scope("prototype")
public class DepAction extends ActionSupport{
	
	private String json;
	private DepManager depManager;
	private String id;
	private String num;
	private String department;
	private String pwd;
	
	//全部部门
	public String dep(){
		json = depManager.get_dep();
		return "json";
	}

	//部门管理
	public String manager(){
		return SUCCESS;
	}
	
	//部门列表
	public String dep_list(){
		json = depManager.dep_list();
		return "json";
	}
	
	//添加部门
	public String dep_add(){
		Dep dep = new Dep();
		dep.setNum(num);
		dep.setDepartment(department);
		json = depManager.dep_add(dep);
		return "json";
	}
	
	//删除部门
	public String dep_del(){
		if(!pwd.equals("569980")){
			json = "{\"status\":1,\"mess\":\"许可密码错误！！\"}";
			return "json";
		}
		Dep dep = new Dep();
		dep.setId(Integer.parseInt(id));
		json = depManager.dep_del(dep);
		return "json";
	}
	
	//修改部门
	public String dep_update(){
		if(!pwd.equals("569980")){
			json = "{\"status\":1,\"mess\":\"许可密码错误！！\"}";
			return "json";
		}
		Dep dep = new Dep();
		dep.setId(Integer.parseInt(id));
		dep.setNum(num);
		dep.setDepartment(department);
		json = depManager.dep_update(dep);
		return "json";
	}
	
	
	
	public String getJson() {
		return json;
	}

	public void setJson(String json) {
		this.json = json;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getNum() {
		return num;
	}

	public void setNum(String num) {
		this.num = num;
	}

	public String getDepartment() {
		return department;
	}

	public void setDepartment(String department) {
		this.department = department;
	}

	public String getPwd() {
		return pwd;
	}

	public void setPwd(String pwd) {
		this.pwd = pwd;
	}

	@Resource(name = "depManager")
	public void setDepManager(DepManager depManager) {
		this.depManager = depManager;
	}
	
	
}
